package 牛客网_N.查找_递归_排序_贪心.maximum_subarray;

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String str = in.nextLine();
		String[] dataStr = str.split(" ");
		int[] A = new int[dataStr.length];
		for(int i = 0; i < dataStr.length; i++){
			A[i] = Integer.parseInt(dataStr[i]);
		}
		System.out.println(maxSubArray(A));
	}
	
	/**
	 * 暴力循环
	 * @param A
	 * @return
	 */
	public static int maxSubArray(int[] A) {
		int max = -1000;
		for(int i = 0; i < A.length-1; i++){
			for(int j = i; j < A.length; j++){
				int sub = 0;
				for(int k = j; k < A.length; k++){
					sub += A[k];
					if(sub > max) max = sub;
				}
			}
		}
		return max;
	}
	
	/**
	 * 贪婪算法 从头开始循环，合为负数则舍去前面这段， 合比Max大则为Max
	 */
	public static int maxSubArray2(int[] A){
		int max = A[0];
		int sub = 0;
		for(int i = 0; i < A.length; i++){
			sub += A[i];
			if(sub > max) max = sub;
			if(sub < 0) sub = 0;
		}
		return max;
	}
}
